package com.hanrui.android.activity.message.myvote;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.widget.TextView;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.hanrui.android.R;
import com.hanrui.android.library.base.ActionBarBaseActivity;
import com.hanrui.android.fragment.message.myvote.MyVoteDetailFragment;
import com.hanrui.android.fragment.message.myvote.MyVoteHandlelFragment;
import com.hanrui.android.fragment.message.myvote.MyVoteRecordFragment;
import com.hanrui.android.widget.bottomnavigationbar.BottomNotYetBar;

import java.util.Stack;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 董事表决（未表决）
 */
public class NotYetVoteActivity extends ActionBarBaseActivity {

    String mid;
    @BindView(R.id.bottomBar)
    BottomNotYetBar bottomApprovalBar;

    MyVoteDetailFragment myVoteDetailFragment;
    MyVoteHandlelFragment myVoteHandlelFragment;
    MyVoteRecordFragment myVoteRecordFragment;

    private Stack<Fragment> stack = new Stack<>();
    FragmentTransaction manager;

    TextView rightTitle;

    @Override
    protected void initInjector() {}

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notyetvote);

        unbinder = ButterKnife.bind(this);

        mTitleBar.setTitle("董事会表决");

        mid = getIntent().getStringExtra("mid");


        initFragment();
        initBottomNav();
        changeFragment(0);

    }

    private void initFragment(){
        manager = getSupportFragmentManager().beginTransaction();

        myVoteDetailFragment = MyVoteDetailFragment.newInstance(mid,"1");
        myVoteHandlelFragment = MyVoteHandlelFragment.newInstance(mid,"1");
        myVoteRecordFragment = MyVoteRecordFragment.newInstance(mid);

        manager.add(R.id.contentContainer, myVoteDetailFragment);
        manager.add(R.id.contentContainer,myVoteHandlelFragment);
        manager.add(R.id.contentContainer,myVoteRecordFragment);

        stack.add(myVoteDetailFragment);
        stack.add(myVoteHandlelFragment);
        stack.add(myVoteRecordFragment);

        manager.commit();
    }

    /*
        初始化底部导航切换事件
     */
    private void initBottomNav(){

        bottomApprovalBar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {
            @Override
            public void onTabSelected(int position) {
                switch (position) {
                    case 0:
                        mTitleBar.setTitle("董事会表决");
                        break;
                    case 1:
                        mTitleBar.setTitle("议案表决");
                        break;
                    case 2:
                        mTitleBar.setTitle("表决情况");
                        break;

                		default:
                			break;
                		}
                changeFragment(position);
            }

            @Override
            public void onTabUnselected(int position) {

            }

            @Override
            public void onTabReselected(int position) {

            }
        });
    }


    /*
        切换Tab，切换对应的Fragment
     */
    private void changeFragment(int position) {
        manager = getSupportFragmentManager().beginTransaction();
        for (Fragment fragment: stack){
            manager.hide(fragment);
        }
        manager.show(stack.get(position));
        manager.commit();
    }

    public static void start(Context context, String mid){

        Intent intent = new Intent(context,NotYetVoteActivity.class);
        intent.putExtra("mid",mid);
        context.startActivity(intent);
    }
}
